﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace SRCBQuestionnaireStatistic.Model
{
    public class QuestionnaireReader
    {
        private int index = -1;
        public int CurrentIndex { get {return index;} }
        public Questionnaire Entity { get; private set; }
        public QuestionnaireReader(Questionnaire entity)
        {
            Entity = entity;
        }
        public Question Question { get { return Entity.Questions[index]; } }
        public void Reset()
        {
            index = -1;
        }
        public void SetIndex(int index)
        {
            this.index = index;
        }

        public bool ReadNext()
        {
            index++;
            bool isNext = index < Entity.Questions.Count;
            if (!isNext)
                MessageBox.Show("没有下一题了！");

            return isNext;
        }

        public bool ReadPrevious()
        {
            if (index == Entity.Questions.Count)
            {
                index--;
            }

            index--;
            bool isPrevious = (index >= 0);
            if (!isPrevious)
            {
                MessageBox.Show("没有上一题了！");
                index++;
            }

            return isPrevious;
        }
    }
}
